<!DOCTYPE html>
<html lang="zh-CN"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>新零售微店后台首页</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/style/admin.css}" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input type="text" name="userNo" id="userNo" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">昵称</label>
                    <div class="layui-input-block">
                        <input type="text" name="userName" id="userName" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search" onclick="SelectData()">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-admin" data-type="add" onclick="WinOpenAdd();">添加</button>
                <button class="layui-btn layuiadmin-btn-admin" data-type="batchdel">删除</button>
                <button class="layui-btn" data-type="getCheckData">获取选中行数据</button>
            </div>

            <table class="layui-hide" id="test"></table>

            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail"  onclick=" WinOpenShow({{d.id}})">查看</a>
                <a class="layui-btn layui-btn-xs" lay-event="edit" onclick="WinOpenEdit({{d.id}})" >编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="DelData({{d.id}})">删除</a>
            </script>

        </div>
    </div>
</div>
<script th:src="@{/layui/layui.js}"></script>
<script th:src="@{/layui/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/shoppingApi/js/jquery-3.3.1.min.js}"></script>
<script type="application/javascript" th:src="@{/shoppingApi/js/common.js}"></script>
<!--<script th:src="@{/js/user/layuiuser.js}"></script>-->
<style>
    .layui-body{overflow-y: scroll;}
</style>
<script th:inline="none">
    var table;
    layui.use('table', function(){
        table = layui.table
            ,form = layui.form;

        table.render({
            elem: '#test'
            ,url:'/user/JsonUserNoList'
            // ,cellMinWidth: 80
            ,cols: [[
                // {type:'numbers'}
                {type: 'checkbox'}
                ,{field:'id', title:'ID'}
                ,{field:'userNo', title:'编号'}
                ,{field:'name', title:'昵称'}
                ,{field:'rank', title: '等级'}
                // ,{field:'angel', title: '天使'}
                // ,{field:'recommend', title: '推荐人'}
                ,{field:'registerTime',width:160 , title: '注册时间',templet :function (row){return createTime(row.registerTime);}}
                ,{field:'id', title:'编辑', templet: '#barDemo', unresize: true}
            ]]
            ,page: true
            ,id: 'testReload'
        });

        //监听表格复选框选择
        table.on('checkbox(demo)', function(obj){
            console.log(obj)
        });


    });





    function createTime(v){
         return new Date(v).getFullYear()+"-"+new Date(v).getMonth()+"-"+new Date(v).getDay()+" "+new Date(v).getHours()+":"+new Date(v).getMinutes()+":"+new Date(v).getSeconds();
    }
    /**重写toLocaleString方法*/
    Date.prototype.toLocaleString = function() {
        var y = this.getFullYear();
        var m = this.getMonth()+1;
        m = m<10?'0'+m:m;
        var d = this.getDate();
        d = d<10?("0"+d):d;
        var h = this.getHours();
        h = h<10?("0"+h):h;
        var M = this.getMinutes();
        M = M<10?("0"+M):M;
        var S=this.getSeconds();
        S=S<10?("0"+S):S;
        return y+"-"+m+"-"+d+" "+h+":"+M+":"+S;}


    function WinOpenAdd() {
        layer.open({
            type: 2
            , title: '添加会员编号'
            , content: '/user/getUserNoAdd'
            , area: ['420px', '420px']
            , btn: ['确定', '取消']
            , yes: function (index, layero) {
                var body = layer.getChildFrame('body', index); //得到iframe页的body内容
                var userName = body.find("#name").val();
                var userNo = body.find("#userNo").val();
                var rankId = body.find("#rankc").val();
                var recommend = body.find("#recommendText").val();
                var recommend = body.find("#recommend").val();
                var sort = body.find("#sort").val();

                var addUrl="/user/addUserNo?userName="+userName+"&phone="+phone+"&cardId="+cardId+"&recommend="+recommend+"&sort="+sort;

                $.ajax({
                    url:addUrl,
                    async:false,
                    success:function (res) {
                        if(res.result=='1'){}
                    }
                });

                //数据刷新
                var demoReload = $('#demoReload');
                //执行重载
                table.reload('testReload', {
                });

                layer.close(index); //关闭弹层
            }
        });
    }

    function WinOpenEdit(id) {
        layer.open({
            type: 2
            , title: '编辑会员编号'
            , content: '/openEditUserNo?id='+id
            , area: ['420px', '420px']
            , btn: ['确定', '取消']
            , yes: function (index, layero) {
                var body = layer.getChildFrame('body', index); //得到iframe页的body内容
                var userNo = body.find("#userNo").val();
                var name = body.find("#name").val();
                var sort = body.find("#sort").val();
                var id=body.find("#id").val();
                $.ajax({
                    type:'post',
                    url:'/saveEditUserNo',
                    data:{
                        userNo:userNo,
                        name:name,
                        sort:sort,
                        id:id
                    },
                    async:false,
                    success: function (res) {
                        if(res.msg=='1'){
                            layer.alert("编辑成功！");
                        }else{
                            layer.alert("编辑失败！");
                        }
                    }
                });
                //执行重载
                table.reload('testReload', {

                });

                layer.close(index); //关闭弹层
            }
        });
    }

    function WinOpenShow(id) {
        layer.open({
            type: 2
            , title: '查看会员编号'
            , content: '/user/getUserNoEdit?id='+id
            , area: ['420px', '420px']
        });
    }

    function DelData(id) {
        layer.open({
            title: '消息'
            , content: '是否确定删除编号为：'+id+' 的数据!!'
            , btn: '确定删除'
            , yes: function () {
                var delUrl = "/delUserNo?id=" + id;
                //alert(delUrl);
                var htmlobj = $.ajax({
                    url: delUrl,
                    async: false,
                    success:function (res) {
                        if(res.msg=='1'){
                            layer.alert("删除成功！");
                        }else{
                            layer.alert("删除失败！");
                        }
                    }
                });
                //alert(htmlobj.responseText);
                //数据刷新
                var demoReload = $('#demoReload');
                //执行重载
                table.reload('testReload', {
                });
                layer.closeAll();
            }
        });
    }


    function SelectData() {
        //数据刷新
        var userNo = $('#userNo').val();
        var userName = $('#userName').val();
        //执行重载
        table.reload('testReload', {
            url:'/user/seachUserNoListByUserNoOrName?userNo='+userNo+'&name='+userName,
            page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    }
</script>


</body>
</html>